import {take,call,put,select} from 'redux-saga/effects'
import {get, post, put_http} from '../axios'
import {actionsTypes as IndexActionTypes} from '../reducers'
import {actionsTypes as CategoryActionTypes} from '../reducers/category'
import history from '../history';

export function* get_list () {
    yield put({type: IndexActionTypes.FETCH_START});
    try {
        return yield call(get, `/mem/project-category`);
    } catch (err) {
        yield put({type: IndexActionTypes.SET_MESSAGE, msgContent: '网络请求错误', msgType: 'fail'});
    } finally {
        yield put({type: IndexActionTypes.FETCH_END})
    }
}

export function* getCategoryListFlow () {
    while (true){
        let req = yield take(CategoryActionTypes.GET_CAT_LIST);
        let res = yield call(get_list);
        if(res){
            if (res.current_page) {
                yield put({type: CategoryActionTypes.RESPONSE_CAT_LIST, data: res})
            } else {
                yield put({type: IndexActionTypes.SET_MESSAGE, msgContent: res.msg, msgType: 'fail'});
            }
        }
    }
}